<template>
	<view>
		<cu-custom bgColor="bg-white" :isBack="true">
			<block slot="backText"></block>
			<block slot="content">门店</block>
		</cu-custom>

		<view class="qui-cells margin-sm radius5" v-for="(item,index) in sourModel" :key="index" @tap="lookPosition(item)">
			<view class="qui-cell flex-start">
				<view class="cell-hd">
					<image :src="img_htp+'/'+item.ShopPhoto" class="shopimg"></image>
				</view>
				<view class="cell-bd">
					<view class="fs30 fw600" v-text="item.ShopName"></view>
					<view>
						<image :src="imgurl+'/icon_time.png'" class="img22 mr10"></image>
						<text class="fs24 text-gray">周{{item.SelectWeek}} {{item.OpenTime}}</text>
					</view>
					<view>
						<image :src="imgurl+'/icon_phone.png'" class="img22 mr10"></image>
						<text class="fs24 text-gray" v-text="item.ShopTel"></text>
					</view>
					<view>
						<image :src="imgurl+'/icon_address.png'" class="img22 mr10"></image>
						<text class="fs24 text-gray" v-text="item.ShopAddress"></text>
					</view>
				</view>
				<view class="cell-ft">
					<text class="fs22 text-gray mr10">距您{{item.Distance||0 }}m</text>
					<image :src="imgurl+'/icon_map.png'" class="img36"></image>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import tools from 'utils/tools.js';
	import base from 'utils/base.js';
	export default {
		data() {
			return {
				imgurl: this.$imgurl,
				img_htp:this.imgurl,
				sourModel: []
			}
		},
		mounted() {
			this.lodingInitPage();
		},
		methods: {
			lookPosition(item) {
				uni.openLocation({
					latitude: item.Lat,
					longitude: item.Lng,
					scale: 16,
					name: item.ShopName,
					address: item.ShopAddress,
					success: function() {
						
					}
				});
			},
			lodingInitPage(latitude, longitude) {
				uni.showLoading({
					title: '加载中',
					mask: true
				});

				var _this = this;
				//获取用户信息
				let globalData = getApp().globalData;
				let userInfo = globalData.UserInfo;
				var requstData = {
					"Lat": tools.getQueryVariable("lat"),
					"Lng": tools.getQueryVariable("lng")
				}
				let params = {
					hideLoading: true,
					type: 'POST',
					url: '/Activity/GetNearbyStores',
					data: requstData,
					sCallback: function(response) {
						uni.hideLoading();
						if (response.Success) {
							var thisSour = response.Data;
							if ((thisSour || []).length == 0) return false;

							_this.sourModel = thisSour;

							//格式化数据
							_this.sourModel.forEach(function(item) {
								item.Distance = Math.floor(parseFloat(item.Distance) * 100)/ 100;
								
								var weeks = (item.SelectWeek||"").split(",");
								if (weeks.indexOf("false") != -1)
								{
									var week_items = ['一', '二', '三', '四', '五', '六', '日'];
									week.forEach(function(wek, index) {
										if(wek)
											item.SelectWeek+=week_items[index];
									});
								}
								else
									item.SelectWeek="一到周日";
								
							});
							
							console.log(_this.sourModel)

						} else {
							uni.showToast({
								icon: 'none',
								title: response.Msg
							});
						}
					}
				};
				base.ActivityRequest(params);
			},

		},

	}
</script>

<style lang="scss">
	.shopimg {
		width: 126rpx;
		height: 126rpx;
		border-radius: 10rpx;
	}

	.img22 {
		width: 22rpx;
		height: 22rpx;
		position: relative;
		top: 2rpx;
	}

	.img36 {
		width: 36rpx;
		height: 36rpx;
		position: relative;
		top: 8rpx;
	}
</style>
